package com.zpl.order.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.zpl.entity.BaseEnum;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public enum Brand implements BaseEnum {
    LAN(0,"兰蔻"),
    JI(1,"纪梵希"),
    MAC(2,"MAC"),
    YSL(3,"YSL"),
    AMN(4,"阿玛尼"),
    YSLD(5,"雅诗兰黛"),
    XNE(6,"香奈儿"),
    DA(7,"迪奥"),
    SK2(8,"SK2"),
    QB(9,"倩碧"),
    HLZM(10,"海蓝之谜"),
    ZST(11,"资生堂"),
    OLY(12,"欧莱雅"),
    JL(13,"娇兰"),
    LZ(14,"兰芝");


    @EnumValue
    private Integer code;
    private String displayName;

    Brand(Integer code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    @Override
    public String getName() {
        return this.name();
    }

    @JsonValue
    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", this.getCode());
        map.put("displayName", this.getDisplayName());
        return map;
    }

    public static JSONArray toJson() {
        JSONArray jsonArray = new JSONArray();
        for (Brand e : Brand.values()) {
            JSONObject object = new JSONObject();
            object.put("code", e.getCode());
            object.put("displayName", e.getDisplayName());
            jsonArray.add(object);
        }
        return jsonArray;
    }
    @JsonCreator
    public static String getDisplayNameByCode(String code) {
        String displayName="";
        for (Brand ele : values()) {
            if (ele.getCode().equals(Integer.valueOf(code))) {
                displayName=ele.getDisplayName();
                break;
            }
        }
        return displayName;
    }
}
